const express = require('express');
const router = express.Router();
const {
  addTrafficReport,
  getAllTrafficReport,
  updateTrafficReportStatus,
} = require('../../services/index');

const { verifyToken, checkRole } = require('../auth');

// 添加信息
router.post('/add', verifyToken, async (req, res) => {
  console.log(req.body);
  let result = await addTrafficReport(req.body);
  res.json(result);
});

//查询所有
router.get(
  '/',
  verifyToken,
  checkRole(['admin', 'traffic']),
  async (req, res) => {
    const result = await getAllTrafficReport();
    res.json(result);
  }
);

//修改状态
router.post(
  '/updateStatus',
  verifyToken,
  checkRole(['admin', 'traffic']),
  async (req, res) => {
    const result = await updateTrafficReportStatus(req.body);
    res.json(result);
  }
);

module.exports = router;
